#pragma once
#include "GraphicsDevice.h"
//#include <vector>
#include <string>
#include "..\base\Settings.h"
#include <map>
#include "RenderTarget.h"
#include "Camera.h"
#include "..\nodes\Node.h"
#include "..\content\ResManager.h"
#include "..\game\World.h"
#include <vector>

namespace ds {

class Light;
class IRenderStage;
class ScreenOverlayNode;

enum RenderMode {
	RM_2D, RM_3D
};

class Renderer {

struct RTAssignment {
	ResourceHandle rtHandle;
	std::vector<WorldLayer> layers;
};

typedef List<Light*> Lights;
typedef std::map<D3DRENDERSTATETYPE,DWORD> RenderStates;
typedef List<IRenderStage*> RenderStages;
typedef List<RTAssignment> Assignments;

public:
	Renderer(HWND hWnd,const Settings& settings);
	~Renderer();
	// basic methods
	void render();
	void init();
	bool Reset();
	LPDIRECT3DDEVICE9 getDevice() { return device->get();}
	GraphicsDevice* getGraphicsDevice() {
		return device;
	}
	// basic rendering methods
	bool beginRendering(const Color& clearColor);
	void endRendering();	
	bool Windowed;
	bool rendering;
	const D3DXMATRIX& getWVPMatrix() const { return matWorldViewProj; }
	const D3DXMATRIX& getWorldMatrix() const { return m_World; }
	const D3DXMATRIX getViewMatrix() const { return m_Camera->getViewMatrix(); }
	const D3DXMATRIX& getProjectionMatrix() const { return m_Camera->getProjectionMatrix();}
	Camera* getCamera();	
	void set2DCameraOn();
	void set2DCameraOff();
	// render state management
	void getRenderStates();
	void setRenderState(D3DRENDERSTATETYPE rs,DWORD value);
	DWORD getRenderState(D3DRENDERSTATETYPE rs);
	RenderMode getRenderMode() { return m_RenderMode; }
	void setupMatrices();
	void applyTransformation(Node* node);
	void prepareDefaultRendering();
	//
	void assignRenderTarget(ResourceHandle rh,WorldLayer layer);
private:	
	void setTransformations();
	void handleRenderTargets();
	RenderMode m_RenderMode;	
	D3DCAPS9 m_DeviceCaps;	
	Camera* m_Camera;	
	D3DXMATRIX matWorldViewProj;
	D3DXMATRIX m_World;
	GraphicsDevice *device;
	RenderStates m_RenderStates;
	Color m_ClearColor;
	int mode;
	RenderTarget* m_RenderTarget;
	RenderStages m_RenderStages;
	ScreenOverlayNode* m_OverlayNode;
	bool m_PostProcessing;
	Assignments m_Assignments;
	List<Node*> list;
};

};